class Watcher {
    constructor (vm, key, cb) {
        this.vm = vm
        this.key = key
        this.cb = cb

        // 把watcher对象存储到Dep.target中
        Dep.target = this

        this.oldValue = this.vm[this.key]

        Dep.target = null
    }

    // 当数据变化的时候 用于更新视图
    update () {
        const newValue = this.vm[this.key]
        if(newValue === this.oldValue) return 

        this.cb(newValue)
    }
}